package petClinic;

import java.util.Properties;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;

public class HibernateUtil {

	private static final SessionFactory factory;
	
	static{
//		ServiceRegistryBuilder serviceRegistryBuilder = new ServiceRegistryBuilder();
//		serviceRegistryBuilder.applySettings(getProperties());
//		ServiceRegistry serviceRegistry = serviceRegistryBuilder.buildServiceRegistry();
		Configuration configuration = new Configuration();
		configuration.addProperties(getProperties());
		// not mapping person
		//configuration.addAnnotatedClass(Person.class);
		configuration.addAnnotatedClass(Vet.class);
		configuration.addAnnotatedClass(PetOwner.class);
		configuration.addAnnotatedClass(Pet.class);
		configuration.addAnnotatedClass(PetVisit.class);
		configuration.addAnnotatedClass(VetSpecialty.class);
		factory = configuration.buildSessionFactory();
	}
	
	private HibernateUtil(){
		/* Helper */
	}
	
	public synchronized static SessionFactory getSessionFactory(){
		return factory;
	}

	private static Properties getProperties(){
		Properties properties = new Properties();
		
		properties.setProperty(Environment.URL, "jdbc:mysql://localhost:3306/petclinic");
		properties.setProperty(Environment.DRIVER, "com.mysql.jdbc.Driver");
		properties.setProperty(Environment.USER, "root");
		properties.setProperty(Environment.DIALECT, "org.hibernate.dialect.MySQL5Dialect");
		properties.setProperty(Environment.PASS, "globant");
		properties.setProperty(Environment.HBM2DDL_AUTO, "update");
		properties.setProperty(Environment.SHOW_SQL, "true");
		//properties.setProperty(Environment.FORMAT_SQL, "true");
		return properties;
	}	
	
}
